<?php
/**
 * Created by PhpStorm.
 * User: yuguozhen
 * Date: 16/7/29
 * Time: 下午2:13
 */

namespace models\Timer\Count;
class WebAccountModel extends \models\WebAccountModel{
    /**
     * 每日新增内部用户
     * @param $prev_start  开始时间
     * @param $prev_end  结束时间
     * @param TYPE 3-内部用户，1-内部用户
     * @return mixed  数量
     */
    public function INNER_WEB_ACCOUNT($prev_start,$prev_end){
        $count = $this->Count($prev_start,$prev_end,3);
        return $count;
    }


    //每日新增外部用户
    public function EXTERNAL_WEB_ACCOUNT($prev_start,$prev_end){
        $count = $this->Count($prev_start,$prev_end,1);
        return $count;
    }

    //每日新增用户
    public function WEB_ACCOUNT($prev_start,$prev_end){
        $count = $this->allCount($prev_start,$prev_end);
        return $count;
    }

    public function Count($prev_start,$prev_end,$type){
        $count = $this->leftJoin('role', 'web_account.USER_TYPE_ID', '=', 'role.id')
//            ->where('web_account.VALID_FLAG','=','ENABLE')
            ->where('role.TYPE','=',$type)
            ->where('web_account.CREATE_TIME','>=',$prev_start)
            ->where('web_account.CREATE_TIME','<=',$prev_end)
            ->count();

        $sql = "select count(1) from `web_account` left join role on web_account.USER_TYPE_ID = role.id where
role.TYPE = ".$type." and web_account.CREATE_TIME >= ".$prev_start." and web_account.CREATE_TIME <= ".$prev_end;
      //  $errpath = $this->config->logs->exec_timer_static_sql;
//        $this->monolog('exec_sql_static',$errpath,$level=\Monolog\Logger::INFO,$content=$sql,$slevel='info');

        return $count;
    }

    public function allCount($prev_start,$prev_end){
        $count = $this->where('CREATE_TIME','>=',$prev_start)
            ->where('CREATE_TIME','<=',$prev_end)
            ->count();

        $sql = "select count(1) from `web_account` where CREATE_TIME >= ".$prev_start." and CREATE_TIME <= ".$prev_end;
     //   $errpath = $this->config->logs->exec_timer_static_sql;
//        $this->monolog('exec_sql_static',$errpath,$level=\Monolog\Logger::INFO,$content=$sql,$slevel='info');

        return $count;
    }

}